using System.Linq;
using CxRomos.Core.Domain;
using CxRomos.Core.Domain.Entities;
using StructureMap;

namespace CxRomos.Core.DataAccess.Implementation {
    [Pluggable("Default")]
    public class TermRepository : RepositoryBase, ITermRepository {
        public Term GetCurrentTerm() {
            var terms = (from t in Context.Terms
                         orderby t.CreateDate descending
                         select t).Take(1);

            Term returnItem = null;
            foreach (var term in terms) {
                returnItem = term;
            }

            return returnItem;
        }

        public void SaveTerm(Term term) {
            BeginTransaction();
            NHibernateSession.SaveOrUpdate(term);
        }

        public void DeleteTerm(Term term) {
            BeginTransaction();
            NHibernateSession.Delete(term);
        }
    }
}